Skip to content

Conversation

@rkistner
Copy link
Contributor

Replication could fail with this error:

Replication error Document is larger than the maximum size 16777216

MongoInvalidArgumentError: Document is larger than the maximum size 16777216
    at UnorderedBulkOperation.addToOperationsList (/app/node_modules/.pnpm/[email protected][email protected]/node_modules/mongodb/lib/bulk/unordered.js:30:19
   ...

We already have a maximum size check for 15MB for storing "current_data". However, that checks BSON size, while the actual synced documents use JSON, which could be larger. So there is a small range of sizes that would pass the size check, but then fail when persisting, breaking the entire replication process. This adds a check for the JSON size, skipping these rows.

@changeset-bot
Copy link

changeset-bot bot commented Mar 10, 2025

🦋 Changeset detected

Latest commit: e870628

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
@powersync/service-module-mongodb-storage Patch
@powersync/lib-service-mongodb Patch
@powersync/service-image Patch
@powersync/service-module-mongodb Patch
@powersync/service-module-mysql Patch
@powersync/service-module-postgres Patch
@powersync/service-core Patch
@powersync/service-core-tests Patch
@powersync/service-module-postgres-storage Patch
test-client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This pull request adds a JSON size check for rows during replication to prevent errors caused by oversized documents while syncing.

  • Update changeset metadata to indicate patch versions and describe the skipping of large rows.
  • Add a check in PersistedBatch.ts to bypass rows whose JSON size exceeds MAX_ROW_SIZE and log an error.
  • Export MAX_ROW_SIZE from MongoBucketBatch.ts and update MongoDB dependency versions in pnpm-lock.yaml.

Reviewed Changes

File Description
.changeset/fast-flowers-scream.md Updated changeset metadata to reflect the new behavior and patched package versions
modules/module-mongodb-storage/src/storage/implementation/PersistedBatch.ts Introduces a JSON size check to skip large rows, preventing replication failures
modules/module-mongodb-storage/src/storage/implementation/MongoBucketBatch.ts Exports the MAX_ROW_SIZE constant for external usage
pnpm-lock.yaml Updates mongodb dependency versions to support the new changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

@rkistner rkistner merged commit 7d1cd98 into main Mar 10, 2025
19 checks passed
@rkistner rkistner deleted the skip-large-rows branch March 10, 2025 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants